using System;
using System.Data;
using System.Data.SqlClient ;


public partial class JobSeekers_resumedetails: System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        if (Session["ResumeID"] == null)
        {
            Response.Redirect("resume.aspx");
        }
        if (!IsPostBack)
        {
            ResumeStatus.Value = Convert.ToString(Session["ResumeStatus"]);
            ResumeID.Value= Session["ResumeID"].ToString();
            EditResume(Session["ResumeID"].ToString());
        }    
    }
    void EditResume(string resumeID)
    {
        if (resumeID != "")
        {
            SQLServerProviders cls = new SQLServerProviders();
            DataTable dataTable =
            cls.GetDataTable("select D.* from " +
            " tblJSResumes,tblJSResumeDetails D where UserID='" 
            + Session["jsuserid"] +
             "' and D.ResumeID='" + resumeID
             + "'", CommandType.Text);
            if(dataTable.Rows.Count>0)
            {
                txtPosition.Text=dataTable.Rows[0][1].ToString();
                ddlCategory.SelectedValue=dataTable.Rows[0][2].ToString();
                ddlIndustry.SelectedValue=dataTable.Rows[0][3].ToString();
                ddlProvince.SelectedValue=dataTable.Rows[0][4].ToString();
                txtCity.Text=dataTable.Rows[0][5].ToString();
                txtStartSalary.Text=dataTable.Rows[0][6].ToString();
                txtEndSalary.Text =dataTable.Rows[0][7].ToString();
                ddlCurrency.SelectedValue=dataTable.Rows[0][8].ToString();
                chkNegotive.Checked=((dataTable.Rows[0][9].ToString()=="True")?true:false);
                chkRalocate.Checked=((dataTable.Rows[0][10].ToString()=="True")?true:false);
                rblType.SelectedValue=dataTable.Rows[0][11].ToString();
                rblLevel.SelectedValue=dataTable.Rows[0][12].ToString();
                ddlStatus.SelectedValue = dataTable.Rows[0][13].ToString();
                txtDescription.Text = dataTable.Rows[0][14].ToString();
            }
        }
    }
    protected void btnNext_Click(object sender, EventArgs e)
    {
        
        SQLServerProviders cls = new SQLServerProviders();
        if (!cls.AddNewUpdateResume(
        (ResumeStatus.Value == "New"),
        ResumeID.Value,
        txtPosition.Text,
        ddlCategory.SelectedValue,
        ddlIndustry.SelectedValue, 
        ddlProvince.SelectedValue,
        txtCity.Text,txtStartSalary.Text,
        txtEndSalary.Text,        
        ddlCurrency.SelectedValue,
        chkNegotive.Checked,
        chkRalocate.Checked,
        rblType.SelectedValue,
        rblLevel.SelectedValue,
        ddlStatus.SelectedValue,
        txtDescription.Text))
            literalError.Text = "Error: " + cls.ErrorMessage;
        else
        {     
            if(Session["ResumeStatus"].ToString() == "Update")
            {
                Session.Remove("ResumeID");
                Response.Redirect("resumes.aspx");   
            }    
            else
            {
                Session.Remove("ResumeID");
                Session.Remove("ResumeStatus");
                Response.Redirect("other.aspx");
            }
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Session.Remove("ResumeID");
        Session.Remove("ResumeStatus");
        Response.Redirect("thankyou.aspx");
    }
}
